/*
 * @Author: 11 11
 * @Date: 2022-02-18 10:09:38
 * @LastEditors: 11 11
 * @LastEditTime: 2022-09-19 18:54:37
 * @FilePath: \LIBd:\EXC\fw\NB_II\git2\software\exc-tl1-2\SRC\user_src\at_cmd_tx.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/**
 ********************************************************************************
 *
 *文件名称：
 *
 *文件日期：
 *
 *文件描述：
 *
 *文件版本：
 *
 *修改历史：
 *
 ********************************************************************************
 ***/

/*******************************	头文件包含区	**********************************/
#include "at_cmd_tx.h"
#include "module_control.h"

/******************************* 全局变量定义区 **********************************/

sim_type_t simType = SIM_UNKOWN;
main_tx_struct main_tx __attribute__((at(0x10000A00)));

/**
 *********************************************************************************
 *
 *函数名称：void my_usart_send_data(uint8_t* pData,uint16_t Len)
 *
 *函数参数：uint8_t* pData：发送的数据缓冲区 uint16_t Len：数据长度
 *
 *函数返回值：无
 *
 *功能描述：串口发送数据接口函数
 *
 *********************************************************************************
 **/
void my_usart_send_data(uint8_t *pData, uint16_t Len)
{
	LOGD("%s,%d", pData,Len);
	if (Len >= SEND_BUF_SIZE / 2)
	{
		LOGD("error:tx_len error!!return!!!");
		return;
	}
	uart1_send(pData, Len);
	DELAY_UART1;
}


void my_usart_send_data2(uint8_t *pData, uint16_t Len)
{
	uart2_send(pData, Len);
	DELAY_UART2;
}


void my_usart_send_data1(uint8_t *pData, uint16_t Len)
{
	uart0_send(pData, Len);
	DELAY;
}
/**
 *********************************************************************************
 *
 *函数名称：void my_usart_send_data(uint8_t* pData,uint16_t Len)
 *
 *函数参数：uint8_t* pData：发送的数据缓冲区 uint16_t Len：数据长度
 *
 *函数返回值：无
 *
 *功能描述：串口发送数据接口函数
 *
 *********************************************************************************
 **/
void my_usart_send_ERROR(uint8_t *pData)
{
	u16 Len = strlen((char *)pData);
	//LOGD("UP_ERROR:%s\r\n", pData);
	if (Len >= SEND_BUF_SIZE / 2)
	{
		LOGD("error:tx_len error!!return!!!\r\n");
		return;
	}
	uart1_send(pData, Len);
	DELAY_UART1;
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void myitoa(uint8_t *str_in, uint16_t len, uint8_t *str_out)
{ /*索引表*/
	char index[] = "0123456789ABCDEF";
	uint16_t i;
	for (i = 0; i < len; i++)
	{
		*(str_out++) = index[str_in[i] >> 4];
		*(str_out++) = index[str_in[i] & 0x0f];
	}
}

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_Restart(void)
{
	//串口初始化
#if (PROJECT_TYPEDEF == NB)
	WIRELESS_RESET(SET);
	delay_ms(11);
	WIRELESS_RESET(RESET);
	LOGD("NB_ReStart!!!\r\n");

#elif (PROJECT_TYPEDEF == NB_ONENET)
#if 1
	sprintf((char *)main_tx.my_at_sendbuf, "AT+NRB\r\n");
#else
	WIRELESS_RESET(SET);
	delay_ms(11);
	WIRELESS_RESET(RESET);
#endif
	LOGD("NB_ReStart!!!\r\n");
#elif (PROJECT_TYPEDEF == CAT1)
#ifdef OLD_BOARD
	POWER_ON(SET);
	POWER_KEY(RESET);
	delay_ms(60);
	POWER_KEY(SET);
	POWER_ON(RESET);
#else

//	POWER_ON(SET);
//	delay_ms(3);
//	POWER_ON(RESET);
//	POWER_KEY(SET);
//	delay_ms(60);
//	POWER_KEY(RESET);
//		
//		POWER_ON(SET);
//		delay_ms(3);
//		POWER_ON(RESET);
//		delay_ms(12);
//		POWER_KEY(SET);
//		delay_ms(60);
//		POWER_KEY(RESET);‘
	POWER_ON(SET);
	delay_ms(12);
	POWER_ON(RESET);
	delay_ms(30);
	POWER_KEY(SET);
	delay_ms(60);
	POWER_KEY(RESET);
		
	
#endif
	LOGD("CAT1_ReStart!!!\r\n");
#endif

	memset(&reg.R.wireless_run_state, 0, sizeof(reg.R.wireless_run_state));
	// while (1)
	// {
	// 	WDT->EN = 0xbb;
	// }
}

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_ATI(void)
{
#if (PROJECT_TYPEDEF == NB || PROJECT_TYPEDEF == NB_ONENET)
	uart_switch_baud(USART_BPS_115200);
#endif
	sprintf((char *)main_tx.my_at_sendbuf, "ATI\r\n");
}

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_ATE0(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "ATE0\r\n");
	reg.R.wireless_run_state.ati = 1;
}

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_CPIN(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CPIN?\r\n");
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_QCCID(void)
{
#if (PROJECT_TYPEDEF == NB)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+NCCID\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+NCCID?\r\n");
#elif (PROJECT_TYPEDEF == CAT1)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QCCID\r\n");
#endif
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_IMEI(void)
{
#if (PROJECT_TYPEDEF == NB)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CGSN=1\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CGSN=1\r\n");
#elif (PROJECT_TYPEDEF == CAT1)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+GSN\r\n");
#endif
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_CREG(void)
{

#if (PROJECT_TYPEDEF == NB)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CEREG?\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CEREG?\r\n");
#else
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CREG?\r\n");

#endif
}


void AT_TX_QSCLK (void)
{

#if (PROJECT_TYPEDEF == NB)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QSCLK=0\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QSCLK=0\r\n");
#else
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CREG?\r\n");
#endif
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_CGATT_GET(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CGATT?\r\n");
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_QMTCFG_0(void)
{
#if (PROJECT_TYPEDEF == CAT1)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTCFG=\"recv/mode\",0,0,1\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLCREATE\r\n");
#endif
}

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_QMTCFG_1(void)
{
#if (PROJECT_TYPEDEF == CAT1)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTCFG=\"version\",0,4\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLADDOBJ=0,10250,1,\"1\",2,0\r\n");
#endif
}

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_QMTCFG_2(void)
{
#if (PROJECT_TYPEDEF == CAT1)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTCFG=\"qmtping\",0,60\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	//sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLOPEN=0,86400,60\r\n");
	 sprintf((char*)main_tx.my_at_sendbuf, "AT+MIPLOPEN=0,7200,60\r\n");
#endif
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
extern uint32_t ONEent_msgld;
void AT_TX_QMTCFG_3(void)
{
#if (PROJECT_TYPEDEF == CAT1)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTCFG=\"keepalive\",0,120\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLDISCOVERRSP=0,%d,1,3,\"0;1\"\r\n", ONEent_msgld);
#endif
}

#if (PROJECT_TYPEDEF == NB_ONENET || PROJECT_TYPEDEF == NB)
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_CFUN0(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CFUN=0\r\n");
}
void AT_TX_CFUN1(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CFUN=1\r\n");
}
void AT_TX_NCSEARFCN(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+NCSEARFCN\r\n");
}
#endif
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_QMTOPEN(void)
{
#if (PROJECT_TYPEDEF == CAT1)
	#if (IP_PUBLIC == ELSE_IP)
		sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTOPEN=0,\"218.17.17.226\",41883\r\n");
	#elif (IP_PUBLIC == WUHAN_PROTOCOL)
	if(((0 == reg.W.ip_h) && (0 == reg.W.ip_l) && (0 == reg.W.ip_port)) || ((0xFFFF == reg.W.ip_h) && (0xFFFF == reg.W.ip_l) && (0xFFFF == reg.W.ip_port)))
	{
		//sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTOPEN=0,\"220.249.122.130\",5673\r\n");
		sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTOPEN=0,\"220.249.122.130\",25678\r\n");
	}
	else{
		sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTOPEN=0,\"%d.%d.%d.%d\",%d\r\n",(reg.W.ip_h >> 8) & 0xff,(reg.W.ip_h) & 0xff,(reg.W.ip_l >> 8) & 0xff,(reg.W.ip_l) & 0xff,reg.W.ip_port);
	}
	#else
		sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTOPEN=0,\"mqtt.ctwing.cn\",1883\r\n");
		//sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTOPEN=0,\"180.106.148.146\",1883\r\n");
	#endif
	#elif (PROJECT_TYPEDEF == NB_ONENET)
		sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLWRITERSP=0,%d,2\r\n", ONEent_msgld);
	#endif
	


}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_QMTCONN(void)
{
#if (PROJECT_TYPEDEF == CAT1)
#if (IP_PUBLIC == ELSE_IP)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTCONN=0,\"%s\",\"duanz\",\"123456\"\r\n", device_info.imei);
#elif (IP_PUBLIC == WUHAN_PROTOCOL)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTCONN=0,\"%s\"\r\n", device_info.imei);
#else
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTCONN=0,\"10095537%s\",\"exc123456\",\"0ExQpbjFXjEbswRZ0twG-g_-HnGjXUazmHysf1-OdUA\"\r\n", device_info.imei);
	//sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTCONN=0,\"%s\",\"exc\",\"exc4008777189\"\r\n", device_info.imei);
#endif
#elif (PROJECT_TYPEDEF == NB_ONENET)
	//sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLUPDATE=0,86400,1\r\n");
	sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLUPDATE=0,7200,1\r\n");
#endif
	// sprintf((char*)main_tx.my_at_sendbuf, "AT+QMTCONN=0,\"10095537%s\",\"exc123456\",\"0ExQpbjFXjEbswRZ0twG-g_-HnGjXUazmHysf1-OdUA\"\r\n","866222058064661");
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_QMTSUB(void)
{
#if (IP_PUBLIC == ELSE_IP || IP_PUBLIC == WUHAN_PROTOCOL)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTSUB=0,1,\"/DownLink/%s\",0\r\n", device_info.imei);
#else
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTSUB=0,1,\"DownLink\",0\r\n");
#endif
}

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_CSQ(void)
{
	
#if (PROJECT_TYPEDEF == CAT1)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QENG=\"servingcell\"\r\n");
#else
    sprintf((char *)main_tx.my_at_sendbuf, "AT+CSQ\r\n");
#endif
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
uint8_t get_cclk_style = 0;
void AT_TX_CCLK(void)
{
#if (PROJECT_TYPEDEF == NB)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CCLK?\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CCLK?\r\n");
#else
#ifdef CAT1_NETWORK_TIME
	switch(get_cclk_style)
	{
		case 0:
			sprintf((char *)main_tx.my_at_sendbuf, "AT+CCLK?\r\n");
			break;
		case 2:
				//sprintf((char *)main_tx.my_at_sendbuf, "AT+QNTP=1,\"20.189.79.72\"\r\n");    //windows
			sprintf((char *)main_tx.my_at_sendbuf, "AT+QNTP=1,\"time.windows.com\"\r\n");    //windows
			break;
		case 1:
			sprintf((char *)main_tx.my_at_sendbuf, "AT+QNTP=1,\"ntp.aliyun.com\"\r\n");    //阿里云
			//sprintf((char *)main_tx.my_at_sendbuf, "AT+QNTP=1,\"203.107.6.88\"\r\n");    //阿里云
			break;
		case 3:
			sprintf((char *)main_tx.my_at_sendbuf, "AT+QNTP=1,\"time1.cloud.tencent.com\"\r\n"); //腾讯云
			//sprintf((char *)main_tx.my_at_sendbuf, "AT+QNTP=1,\"106.55.184.199\"\r\n"); //腾讯云
			break;
		case 4:
			//sprintf((char *)main_tx.my_at_sendbuf, "AT+QNTP=1,\"cn.pool.ntp.org\"\r\n");   //开源NTP服务器
			sprintf((char *)main_tx.my_at_sendbuf, "AT+QNTP=1,\"202.112.10.36\",123\r\n");   //开源NTP服务器
			break;
		case 5:
			sprintf((char *)main_tx.my_at_sendbuf, "AT+QNTP=1,\"ntp.ntsc.ac.cn\"\r\n");    //中国科学院国家授时中心
			//sprintf((char *)main_tx.my_at_sendbuf, "AT+QNTP=1,\"114.118.7.161\"\r\n");    //中国科学院国家授时中心
			break;
		case 6:
			sprintf((char *)main_tx.my_at_sendbuf, "AT+CCLK?\r\n");
			break;
		default:
			sprintf((char *)main_tx.my_at_sendbuf, "AT+CCLK?\r\n");
			break;
	}
#else
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CCLK?\r\n");
#endif
#endif
}

#if (PROJECT_TYPEDEF == CAT1)
void get_cclk_another_way(void)
{
	get_cclk_style ++;
	if(get_cclk_style > TIMESCOMPARE - 1)
	{
		get_cclk_style = 0;
	}
	my_cmd_deal(AT_CCLK, AT_TX_CCLK, waiting_to_receive, 1, 50000, ACK);
}
void restore_factory_cclk_way(void)
{
	get_cclk_style = 0;	
}

uint16_t send_data_len(volatile uint8_t comm_typedef)
{
	volatile uint16_t len = 0;
	volatile uint8_t i = 0 ,j = 0;
	
	
	if(comm_typedef == 0x10)
	{
		//LOGD("comm_typedef=0x10:%d\r\n", comm_typedef);
		len	= len + 7;
		if (global_control.protocol.reg_addr[i] == 0x201E)
			global_control.protocol.reg_len[i] = 1; //特殊处理，策略包恢复数据长度为1
		
		for (i = 0; i < global_control.protocol.reg_num; i++)
		{
			len = len + 3;
			for (j = 0; j < global_control.protocol.reg_len[i]; j++)
			{
				len = len + 2;
			}
		}
		LOGD("reg_num=0x10:%d\r\n", global_control.protocol.reg_num);
		len = len + 2;
	}
	else if(comm_typedef == 0x3)
	{
		len = (11 + global_control.protocol.reg_len[0] * 2) ;
	//	LOGD("comm_typedef=0x03:%d\r\n", comm_typedef);
	}
	else if(comm_typedef == 0x6)
	{
		len = 12;
	//	LOGD("comm_typedef=0x06:%d\r\n", comm_typedef);
	}
	len = (len + len) + 11;
	return len;
}
#endif
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
extern uint32_t alarm_send_data_flag;
void AT_TX_QMTPUB_UP_LAMP(void)
{
	//LOGD("---------pwower:%u\r\n",reg.R.p1);
	uint16_t data_len = 0, crc, i, j, read_data;
	alarm_send_data_flag = 0;
#if (PROJECT_TYPEDEF == NB)
	main_tx.my_at_sendbuf[0] = 0x02; // 上报02
	main_tx.my_at_sendbuf[1] = 0x00; //
	main_tx.my_at_sendbuf[2] = 0x04; //服务ID为04
	main_tx.my_at_sendbuf[3] = 0x00; //
	data_len = 7;
#endif
#ifdef PUBLIC_PROTOCOL
	main_tx.my_at_sendbuf[data_len++] = reg.R.m_73or63 ? 0x63 : 0x73;
#else
	main_tx.my_at_sendbuf[data_len++] = 0x63;
#endif
	main_tx.my_at_sendbuf[data_len++] = 0x00;
	main_tx.my_at_sendbuf[data_len++] = 0x00;
	main_tx.my_at_sendbuf[data_len++] = 0x00;
	main_tx.my_at_sendbuf[data_len++] = 0x00;
#ifdef PUBLIC_PROTOCOL
	main_tx.my_at_sendbuf[data_len++] = reg.R.m_73or63 ? 0x10 : 0x11;
#else
	main_tx.my_at_sendbuf[data_len++] = 0x10;
#endif
	main_tx.my_at_sendbuf[data_len++] = global_control.protocol.reg_num;
	for (i = 0; i < global_control.protocol.reg_num; i++)
	{
		main_tx.my_at_sendbuf[data_len++] = global_control.protocol.reg_addr[i] >> 8;
		main_tx.my_at_sendbuf[data_len++] = global_control.protocol.reg_addr[i];
		main_tx.my_at_sendbuf[data_len++] = global_control.protocol.reg_len[i];
		for (j = 0; j < global_control.protocol.reg_len[i]; j++)
		{
			read_data = protocol_read(global_control.protocol.reg_addr[i] + j);
			main_tx.my_at_sendbuf[data_len++] = read_data >> 8;
			main_tx.my_at_sendbuf[data_len++] = read_data;
		}
	}
#if (PROJECT_TYPEDEF == NB)
	crc = crc16(main_tx.my_at_sendbuf + 7, data_len - 7);
#elif (PROJECT_TYPEDEF == NB_ONENET)
	crc = crc16(main_tx.my_at_sendbuf, data_len);
#elif (PROJECT_TYPEDEF == CAT1)
	crc = crc16(main_tx.my_at_sendbuf, data_len);
#else
#error "设备类型未定义"
#endif
	main_tx.my_at_sendbuf[data_len++] = crc & 0x00ff;
	main_tx.my_at_sendbuf[data_len++] = crc >> 8;

#if (PROJECT_TYPEDEF == NB)
	main_tx.my_at_sendbuf[3] = (data_len - 5) >> 8; //
	main_tx.my_at_sendbuf[4] = data_len - 5;		//长度为COM_SendLen
	main_tx.my_at_sendbuf[5] = (data_len - 7) >> 8; //
	main_tx.my_at_sendbuf[6] = data_len - 7;		//长度为COM_SendLen
#endif

	myitoa(main_tx.my_at_sendbuf, data_len, main_tx.my_at_data_str);
	// sprintf((char*)my_at_sendbuf, "AT+QMTPUB=0,0,0,0,\"UpLink\",{\"data\":\"%s\"}\r\n", my_at_data_str);
#if (PROJECT_TYPEDEF == NB)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QLWULDATA=%d,%s\r\n", data_len, main_tx.my_at_data_str);
#elif (PROJECT_TYPEDEF == CAT1)
#if (IP_PUBLIC == ELSE_IP || IP_PUBLIC == WUHAN_PROTOCOL)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTPUB=0,0,0,0,\"/UpLink/%s\",{\"data\":\"%s\"}\r\n", device_info.imei, main_tx.my_at_data_str);
#else
	//sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTPUB=0,0,0,0,\"UpLink\",{\"data\":\"%s\"}\r\n", main_tx.my_at_data_str);
	sprintf((char *)main_tx.my_at_sendbuf, "{\"data\":\"%s\"}\r\n", main_tx.my_at_data_str);
#endif
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLNOTIFY=0,0,10250,0,0,2,%d,%s,0,0\r\n", data_len, main_tx.my_at_data_str);
#else
#error "设备类型未定义"
#endif
	if(leakDete.send_lamp1_time_flag == 2)
	{
		leakDete.send_lamp1_time_flag = 3;
	}
	if(leakDete.send_lamp2_time_flag == 2)
	{
		leakDete.send_lamp2_time_flag = 3;
	}
}

#if (PROJECT_TYPEDEF == CAT1)
void AT_TX_UPLINK10(void)
{
	//global_control.error_code = 0;
	volatile uint16_t data_len = send_data_len(0x10);
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTPUBEX=0,0,0,0,\"UpLink\",%d\r\n",data_len);
}

void AT_TX_UPLINK03(void)
{
	//global_control.error_code = 0;
	volatile uint16_t data_len = send_data_len(0x3);
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTPUBEX=0,0,0,0,\"UpLink\",%d\r\n",data_len);
}
void AT_TX_UPLINK06(void)
{
//	global_control.error_code = 0;
	//volatile uint16_t data_len = 0;
	
	//data_len = send_data_len(0x6);
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTPUBEX=0,0,0,0,\"UpLink\",%d\r\n", 35);
	//data_len = 0;
}
#endif

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void send_waiting_to_receive(void)
{
#if (PROJECT_TYPEDEF == NB)
	//LOGD("delay receive!!!\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	//LOGD("delay receive!!!\r\n");
#elif (PROJECT_TYPEDEF == CAT1)
	//LOGD("delay receive!!!\r\n");
#else
#error "设备类型未定义"
#endif
}

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void recv_waiting_to_receive(void)
{
#if (PROJECT_TYPEDEF == NB)
	//LOGD("default fun!!!\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	//LOGD("delay receive!!!\r\n");
#elif (PROJECT_TYPEDEF == CAT1)
	//LOGD("default fun!!!\r\n");
#else
#error "设备类型未定义"
#endif
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_QMTPUB_1007(void)
{
	uint16_t data_len = 0, crc, read_data;
#ifdef PUBLIC_PROTOCOL
	main_tx.my_at_sendbuf[data_len++] = reg.R.m_73or63 ? 0x63 : 0x73;
#else
	main_tx.my_at_sendbuf[data_len++] = 0x63;
#endif
	main_tx.my_at_sendbuf[data_len++] = 0x00;
	main_tx.my_at_sendbuf[data_len++] = 0x00;
	main_tx.my_at_sendbuf[data_len++] = 0x00;
	main_tx.my_at_sendbuf[data_len++] = 0x00;
#ifdef PUBLIC_PROTOCOL
	main_tx.my_at_sendbuf[data_len++] = reg.R.m_73or63 ? 0x06 : 0x61;
#else
	main_tx.my_at_sendbuf[data_len++] = 0x06;
#endif
	main_tx.my_at_sendbuf[data_len++] = 0x10;
	main_tx.my_at_sendbuf[data_len++] = 0x07;
	read_data = protocol_read(0x1007);
	main_tx.my_at_sendbuf[data_len++] = read_data >> 8;
	main_tx.my_at_sendbuf[data_len++] = read_data;

	crc = crc16(main_tx.my_at_sendbuf, data_len);
	main_tx.my_at_sendbuf[data_len++] = crc & 0x00ff;
	main_tx.my_at_sendbuf[data_len++] = crc >> 8;

	myitoa(main_tx.my_at_sendbuf, data_len, main_tx.my_at_data_str);
#if (PROJECT_TYPEDEF == CAT1)
#if (IP_PUBLIC == ELSE_IP || IP_PUBLIC == WUHAN_PROTOCOL)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTPUB=0,0,0,0,\"/UpLink/%s\",{\"data\":\"%s\"}\r\n", device_info.imei, main_tx.my_at_data_str);
#else
	//sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTPUB=0,0,0,0,\"UpLink\",{\"data\":\"%s\"}\r\n", main_tx.my_at_data_str);
	sprintf((char *)main_tx.my_at_sendbuf, "{\"data\":\"%s\"}\r\n", main_tx.my_at_data_str);
#endif
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLNOTIFY=0,0,10250,0,0,2,%d,%s,0,0\r\n", data_len, main_tx.my_at_data_str);
#endif
}

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：
 *
 *********************************************************************************
 **/
void AT_TX_QMTPUB_2018(void)
{
	uint16_t data_len = 0, crc, read_data;
#ifdef PUBLIC_PROTOCOL
	main_tx.my_at_sendbuf[data_len++] = reg.R.m_73or63 ? 0x63 : 0x73;
#else
	main_tx.my_at_sendbuf[data_len++] = 0x63;
#endif
	main_tx.my_at_sendbuf[data_len++] = 0x00;
	main_tx.my_at_sendbuf[data_len++] = 0x00;
	main_tx.my_at_sendbuf[data_len++] = 0x00;
	main_tx.my_at_sendbuf[data_len++] = 0x00;
#ifdef PUBLIC_PROTOCOL
	main_tx.my_at_sendbuf[data_len++] = reg.R.m_73or63 ? 0x06 : 0x61;
#else
	main_tx.my_at_sendbuf[data_len++] = 0x06;
#endif
	main_tx.my_at_sendbuf[data_len++] = 0x20;
	main_tx.my_at_sendbuf[data_len++] = 0x18;
	read_data = protocol_read(0x2018);
	main_tx.my_at_sendbuf[data_len++] = read_data >> 8;
	main_tx.my_at_sendbuf[data_len++] = read_data;

	crc = crc16(main_tx.my_at_sendbuf, data_len);
	main_tx.my_at_sendbuf[data_len++] = crc & 0x00ff;
	main_tx.my_at_sendbuf[data_len++] = crc >> 8;

	myitoa(main_tx.my_at_sendbuf, data_len, main_tx.my_at_data_str);
#if (PROJECT_TYPEDEF == CAT1)
#if (IP_PUBLIC == ELSE_IP || IP_PUBLIC == WUHAN_PROTOCOL)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTPUB=0,0,0,0,\"/UpLink/%s\",{\"data\":\"%s\"}\r\n", device_info.imei, main_tx.my_at_data_str);
#else
	//sprintf((char *)main_tx.my_at_sendbuf, "AT+QMTPUB=0,0,0,0,\"UpLink\",{\"data\":\"%s\"}\r\n", main_tx.my_at_data_str);
	sprintf((char *)main_tx.my_at_sendbuf, "{\"data\":\"%s\"}\r\n", main_tx.my_at_data_str);
#endif
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLNOTIFY=0,0,10250,0,0,2,%d,%s,0,0\r\n", data_len, main_tx.my_at_data_str);
#endif
}

#if (PROJECT_TYPEDEF == NB)

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：查询联网状态
 *
 *********************************************************************************
 **/
// void AEP_PackSend(uint8_t cmd)
uint16_t current_ota_serial = 0;
void APP_PACKsend_inquiry_vereion_19(void)
{
	uint16_t CRC_data = 0;
	// uint8_t COM_SendBuff[50]={0};
	uint16_t COM_SendLen = 0;

	main_tx.my_at_sendbuf[0] = 0xFF;					// 头部
	main_tx.my_at_sendbuf[1] = 0xFE;					//
	main_tx.my_at_sendbuf[2] = 0x01;					//
	main_tx.my_at_sendbuf[3] = mainUart.my_data_buf[3]; //

	main_tx.my_at_sendbuf[6] = 0; //数据长度
	main_tx.my_at_sendbuf[7] = 0x11;
	main_tx.my_at_sendbuf[8] = 0;

	main_tx.my_at_sendbuf[9] = 'V'; // 固件版本号	 0056322E31300000000000000000000000

	main_tx.my_at_sendbuf[10] = reg.R.software_version / 10000 + '0';		   // 固件版本号
	main_tx.my_at_sendbuf[11] = (reg.R.software_version % 10000) / 1000 + '0'; // 固件版本号
	main_tx.my_at_sendbuf[12] = (reg.R.software_version % 1000) / 100 + '0';   // 固件版本号
	main_tx.my_at_sendbuf[13] = (reg.R.software_version % 100) / 10 + '0';	   // 固件版本号
	main_tx.my_at_sendbuf[14] = reg.R.software_version % 10 + '0';			   // 固件版本号

	COM_SendLen = (main_tx.my_at_sendbuf[6] << 8) + main_tx.my_at_sendbuf[7] + 8;
	CRC_data = do_crc(0x0000, main_tx.my_at_sendbuf, COM_SendLen);
	main_tx.my_at_sendbuf[4] = CRC_data >> 8; // crcH
	main_tx.my_at_sendbuf[5] = CRC_data;	  // crcL

	myitoa(main_tx.my_at_sendbuf, COM_SendLen, main_tx.my_at_data_str);
	main_tx.my_at_sendbuf[8] = COM_SendLen / 10 + '0';
	main_tx.my_at_sendbuf[9] = COM_SendLen % 10 + '0';

	sprintf((char *)main_tx.my_at_sendbuf, "AT+NMGS=%d,%s\r\n", COM_SendLen, main_tx.my_at_data_str);
}
uint8_t OTA_Result_flag = 0;
void APP_PACKsend_vereion_notify_20(void)
{
	uint16_t CRC_data = 0;
	uint16_t COM_SendLen = 0;

	main_tx.my_at_sendbuf[0] = 0xFF;					// 头部
	main_tx.my_at_sendbuf[1] = 0xFE;					//
	main_tx.my_at_sendbuf[2] = 0x01;					//
	main_tx.my_at_sendbuf[3] = mainUart.my_data_buf[3]; //
	main_tx.my_at_sendbuf[6] = 0;						//数据长度
	main_tx.my_at_sendbuf[7] = 0x01;

	main_tx.my_at_sendbuf[8] = OTA_Result_flag;

	COM_SendLen = (main_tx.my_at_sendbuf[6] << 8) + main_tx.my_at_sendbuf[7] + 8;
	CRC_data = do_crc(0x0000, main_tx.my_at_sendbuf, COM_SendLen);
	main_tx.my_at_sendbuf[4] = CRC_data >> 8; // crcH
	main_tx.my_at_sendbuf[5] = CRC_data;	  // crcL

	myitoa(main_tx.my_at_sendbuf, COM_SendLen, main_tx.my_at_data_str);
	main_tx.my_at_sendbuf[8] = COM_SendLen / 10 + '0';
	main_tx.my_at_sendbuf[9] = COM_SendLen % 10 + '0';

	sprintf((char *)main_tx.my_at_sendbuf, "AT+NMGS=%d,%s\r\n", COM_SendLen, main_tx.my_at_data_str);
}
void APP_PACKsend_request_ota_pack_21(void)
{
	uint16_t CRC_data = 0;
	uint16_t COM_SendLen = 0;

	main_tx.my_at_sendbuf[0] = 0xFF;					// 头部
	main_tx.my_at_sendbuf[1] = 0xFE;					//
	main_tx.my_at_sendbuf[2] = 0x01;					//
	main_tx.my_at_sendbuf[3] = mainUart.my_data_buf[3]; //

	main_tx.my_at_sendbuf[6] = 0; //数据长度
	main_tx.my_at_sendbuf[7] = 0x12;

	main_tx.my_at_sendbuf[8] = 'V'; // 固件版本号	 56322E31360000000000000000000000

	main_tx.my_at_sendbuf[9] = reg.RW.OTA_new_version / 10000 + '0';		   // 固件版本号
	main_tx.my_at_sendbuf[10] = (reg.RW.OTA_new_version % 10000) / 1000 + '0'; // 固件版本号
	main_tx.my_at_sendbuf[11] = (reg.RW.OTA_new_version % 1000) / 100 + '0';   // 固件版本号
	main_tx.my_at_sendbuf[12] = (reg.RW.OTA_new_version % 100) / 10 + '0';	   // 固件版本号
	main_tx.my_at_sendbuf[13] = reg.RW.OTA_new_version % 10 + '0';			   // 固件版本号

	main_tx.my_at_sendbuf[24] = current_ota_serial >> 8;
	main_tx.my_at_sendbuf[25] = current_ota_serial;

	COM_SendLen = (main_tx.my_at_sendbuf[6] << 8) + main_tx.my_at_sendbuf[7] + 8;
	CRC_data = do_crc(0x0000, main_tx.my_at_sendbuf, COM_SendLen);
	main_tx.my_at_sendbuf[4] = CRC_data >> 8; // crcH
	main_tx.my_at_sendbuf[5] = CRC_data;	  // crcL

	myitoa(main_tx.my_at_sendbuf, COM_SendLen, main_tx.my_at_data_str);
	main_tx.my_at_sendbuf[8] = COM_SendLen / 10 + '0';
	main_tx.my_at_sendbuf[9] = COM_SendLen % 10 + '0';

	sprintf((char *)main_tx.my_at_sendbuf, "AT+NMGS=%d,%s\r\n", COM_SendLen, main_tx.my_at_data_str);
}

void APP_PACKsend_report_ota_status_22(void)
{
	uint16_t CRC_data = 0;
	uint16_t COM_SendLen = 0;

	main_tx.my_at_sendbuf[0] = 0xFF;					// 头部
	main_tx.my_at_sendbuf[1] = 0xFE;					//
	main_tx.my_at_sendbuf[2] = 0x01;					//
	main_tx.my_at_sendbuf[3] = mainUart.my_data_buf[3]; //

	if (reg.RW.ota_flag == OTA_PACKAGE_RX_OK)
	{
		// reg.RW.ota_flag = NONE_OTA;
	}
	else
	{
		/***do nothing***/
	}
	main_tx.my_at_sendbuf[6] = 0; //数据长度
	main_tx.my_at_sendbuf[7] = 0x01;
	main_tx.my_at_sendbuf[8] = OTA_Result_flag;

	COM_SendLen = (main_tx.my_at_sendbuf[6] << 8) + main_tx.my_at_sendbuf[7] + 8;
	CRC_data = do_crc(0x0000, main_tx.my_at_sendbuf, COM_SendLen);
	main_tx.my_at_sendbuf[4] = CRC_data >> 8; // crcH
	main_tx.my_at_sendbuf[5] = CRC_data;	  // crcL

	myitoa(main_tx.my_at_sendbuf, COM_SendLen, main_tx.my_at_data_str);
	main_tx.my_at_sendbuf[8] = COM_SendLen / 10 + '0';
	main_tx.my_at_sendbuf[9] = COM_SendLen % 10 + '0';

	sprintf((char *)main_tx.my_at_sendbuf, "AT+NMGS=%d,%s\r\n", COM_SendLen, main_tx.my_at_data_str);
}
void APP_PACKsend_start_ota_23(void)
{
	uint16_t CRC_data = 0;
	uint16_t COM_SendLen = 0;

	main_tx.my_at_sendbuf[0] = 0xFF;					// 头部
	main_tx.my_at_sendbuf[1] = 0xFE;					//
	main_tx.my_at_sendbuf[2] = 0x01;					//
	main_tx.my_at_sendbuf[3] = mainUart.my_data_buf[3]; //

	main_tx.my_at_sendbuf[6] = 0; //数据长度
	main_tx.my_at_sendbuf[7] = 0x00;
	COM_SendLen = (main_tx.my_at_sendbuf[6] << 8) + main_tx.my_at_sendbuf[7] + 8;
	CRC_data = do_crc(0x0000, main_tx.my_at_sendbuf, COM_SendLen);
	main_tx.my_at_sendbuf[4] = CRC_data >> 8; // crcH
	main_tx.my_at_sendbuf[5] = CRC_data;	  // crcL

	myitoa(main_tx.my_at_sendbuf, COM_SendLen, main_tx.my_at_data_str);
	main_tx.my_at_sendbuf[8] = COM_SendLen / 10 + '0';
	main_tx.my_at_sendbuf[9] = COM_SendLen % 10 + '0';

	sprintf((char *)main_tx.my_at_sendbuf, "AT+NMGS=%d,%s\r\n", COM_SendLen, main_tx.my_at_data_str);
}
void APP_PACKsend_report_ota_result_24(void)
{
	uint16_t CRC_data = 0;
	uint16_t COM_SendLen = 0;

	main_tx.my_at_sendbuf[0] = 0xFF;					// 头部
	main_tx.my_at_sendbuf[1] = 0xFE;					//
	main_tx.my_at_sendbuf[2] = 0x01;					//
	main_tx.my_at_sendbuf[3] = mainUart.my_data_buf[3]; //
	main_tx.my_at_sendbuf[6] = 0;						//数据长度
	main_tx.my_at_sendbuf[7] = 0x11;

	main_tx.my_at_sendbuf[8] = 0;

	main_tx.my_at_sendbuf[9] = 'V'; // 固件版本号	 56322E31360000000000000000000000

	main_tx.my_at_sendbuf[10] = reg.RW.OTA_new_version / 10000 + '0';		   // 固件版本号
	main_tx.my_at_sendbuf[11] = (reg.RW.OTA_new_version % 10000) / 1000 + '0'; // 固件版本号
	main_tx.my_at_sendbuf[12] = (reg.RW.OTA_new_version % 1000) / 100 + '0';   // 固件版本号
	main_tx.my_at_sendbuf[13] = (reg.RW.OTA_new_version % 100) / 10 + '0';	   // 固件版本号
	main_tx.my_at_sendbuf[14] = reg.RW.OTA_new_version % 10 + '0';			   // 固件版本号

	main_tx.my_at_sendbuf[15] = 0;
	main_tx.my_at_sendbuf[16] = 0;
	main_tx.my_at_sendbuf[17] = 0;
	main_tx.my_at_sendbuf[18] = 0;
	main_tx.my_at_sendbuf[19] = 0;
	main_tx.my_at_sendbuf[20] = 0;
	main_tx.my_at_sendbuf[21] = 0;
	main_tx.my_at_sendbuf[22] = 0;
	main_tx.my_at_sendbuf[23] = 0;
	main_tx.my_at_sendbuf[24] = 0;
	COM_SendLen = (main_tx.my_at_sendbuf[6] << 8) + main_tx.my_at_sendbuf[7] + 8;
	CRC_data = do_crc(0x0000, main_tx.my_at_sendbuf, COM_SendLen);
	main_tx.my_at_sendbuf[4] = CRC_data >> 8; // crcH
	main_tx.my_at_sendbuf[5] = CRC_data;	  // crcL

	myitoa(main_tx.my_at_sendbuf, COM_SendLen, main_tx.my_at_data_str);
	main_tx.my_at_sendbuf[8] = COM_SendLen / 10 + '0';
	main_tx.my_at_sendbuf[9] = COM_SendLen % 10 + '0';

	sprintf((char *)main_tx.my_at_sendbuf, "AT+NMGS=%d,%s\r\n", COM_SendLen, main_tx.my_at_data_str);
}
void AEP_PackSend(void)
{
	uint16_t CRC_data = 0;
	uint16_t COM_SendLen = 0;

	main_tx.my_at_sendbuf[0] = 0xFF;					// 头部
	main_tx.my_at_sendbuf[1] = 0xFE;					//
	main_tx.my_at_sendbuf[2] = 0x01;					//
	main_tx.my_at_sendbuf[3] = mainUart.my_data_buf[3]; //

#if 1

	if (mainUart.my_data_buf[3] == 19)
	{
		main_tx.my_at_sendbuf[6] = 0; //数据长度
		main_tx.my_at_sendbuf[7] = 0x11;
		main_tx.my_at_sendbuf[8] = 0;

		main_tx.my_at_sendbuf[9] = 'V'; // 固件版本号	 56322E31360000000000000000000000

		main_tx.my_at_sendbuf[10] = reg.R.software_version / 10000 + '0';		   // 固件版本号
		main_tx.my_at_sendbuf[11] = (reg.R.software_version % 10000) / 1000 + '0'; // 固件版本号
		main_tx.my_at_sendbuf[12] = (reg.R.software_version % 1000) / 100 + '0';   // 固件版本号
		main_tx.my_at_sendbuf[13] = (reg.R.software_version % 100) / 10 + '0';	   // 固件版本号
		main_tx.my_at_sendbuf[14] = reg.R.software_version % 10 + '0';			   // 固件版本号
	}
	else if (mainUart.my_data_buf[3] == 20)
	{
		main_tx.my_at_sendbuf[6] = 0; //数据长度
		main_tx.my_at_sendbuf[7] = 0x01;

		main_tx.my_at_sendbuf[8] = 0;
	}

	else if (mainUart.my_data_buf[3] == 21)
	{
		main_tx.my_at_sendbuf[6] = 0; //数据长度
		main_tx.my_at_sendbuf[7] = 0x12;

		main_tx.my_at_sendbuf[8] = 'V'; // 固件版本号	 56322E31360000000000000000000000

		main_tx.my_at_sendbuf[9] = reg.RW.OTA_new_version / 10000 + '0';		   // 固件版本号
		main_tx.my_at_sendbuf[10] = (reg.RW.OTA_new_version % 10000) / 1000 + '0'; // 固件版本号
		main_tx.my_at_sendbuf[11] = (reg.RW.OTA_new_version % 1000) / 100 + '0';   // 固件版本号
		main_tx.my_at_sendbuf[12] = (reg.RW.OTA_new_version % 100) / 10 + '0';	   // 固件版本号
		main_tx.my_at_sendbuf[13] = reg.RW.OTA_new_version % 10 + '0';			   // 固件版本号

		main_tx.my_at_sendbuf[24] = current_ota_serial >> 8;
		main_tx.my_at_sendbuf[25] = current_ota_serial;
	}
	else if (mainUart.my_data_buf[3] == 22) //上报下载结果
	{
		if (reg.RW.ota_flag != OTA_FAIL)
		{
			main_tx.my_at_sendbuf[6] = 0; //数据长度
			main_tx.my_at_sendbuf[7] = 0x01;
			main_tx.my_at_sendbuf[8] = 0;
		}
		else
		{
			main_tx.my_at_sendbuf[6] = 0; //数据长度
			main_tx.my_at_sendbuf[7] = 0x01;
			reg.RW.ota_flag = NONE_OTA;
			main_tx.my_at_sendbuf[8] = 7;
		}

		// in_tx.my_at_sendbuf[8] = Upgrape_res;
	}

	else if (mainUart.my_data_buf[3] == 23) //执行升级应答
	{
		main_tx.my_at_sendbuf[6] = 0; //数据长度
		main_tx.my_at_sendbuf[7] = 0x00;
	}

	else if (mainUart.my_data_buf[3] == 24) //上报升级结果应答
	{
		main_tx.my_at_sendbuf[6] = 0; //数据长度
		main_tx.my_at_sendbuf[7] = 0x11;

		main_tx.my_at_sendbuf[8] = 0;

		main_tx.my_at_sendbuf[9] = 'V'; // 固件版本号	 56322E31360000000000000000000000

		main_tx.my_at_sendbuf[10] = reg.RW.OTA_new_version / 10000 + '0';		   // 固件版本号
		main_tx.my_at_sendbuf[11] = (reg.RW.OTA_new_version % 10000) / 1000 + '0'; // 固件版本号
		main_tx.my_at_sendbuf[12] = (reg.RW.OTA_new_version % 1000) / 100 + '0';   // 固件版本号
		main_tx.my_at_sendbuf[13] = (reg.RW.OTA_new_version % 100) / 10 + '0';	   // 固件版本号
		main_tx.my_at_sendbuf[14] = reg.RW.OTA_new_version % 10 + '0';			   // 固件版本号

		main_tx.my_at_sendbuf[15] = 0;
		main_tx.my_at_sendbuf[16] = 0;
		main_tx.my_at_sendbuf[17] = 0;
		main_tx.my_at_sendbuf[18] = 0;
		main_tx.my_at_sendbuf[19] = 0;
		main_tx.my_at_sendbuf[20] = 0;
		main_tx.my_at_sendbuf[21] = 0;
		main_tx.my_at_sendbuf[22] = 0;
		main_tx.my_at_sendbuf[23] = 0;
		main_tx.my_at_sendbuf[24] = 0;
	}

	COM_SendLen = (main_tx.my_at_sendbuf[6] << 8) + main_tx.my_at_sendbuf[7] + 8;
	CRC_data = do_crc(0x0000, main_tx.my_at_sendbuf, COM_SendLen);
	main_tx.my_at_sendbuf[4] = CRC_data >> 8; // crcH
	main_tx.my_at_sendbuf[5] = CRC_data;	  // crcL

	myitoa(main_tx.my_at_sendbuf, COM_SendLen, main_tx.my_at_data_str);
	main_tx.my_at_sendbuf[8] = COM_SendLen / 10 + '0';
	main_tx.my_at_sendbuf[9] = COM_SendLen % 10 + '0';

	sprintf((char *)main_tx.my_at_sendbuf, "AT+NMGS=%d,%s\r\n", COM_SendLen, main_tx.my_at_data_str);
#endif
}

#endif
#if (PROJECT_TYPEDEF == NB || PROJECT_TYPEDEF == NB_ONENET)
void AT_TX_NMSTATUS(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+NMSTATUS?\r\n");
}
void AT_TX_SWITCH_BAUD(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+NATSPEED=115200,30,1,3,1,0,0\r\n");
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：配置华为生命周期
 *
 *********************************************************************************
 **/
void AT_TX_QCFG(void)
{
#if (PROJECT_TYPEDEF == NB)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QCFG=\"LWM2M/Lifetime\",72000\r\n");
#elif (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLCONFIG=0,192.168.24.100,5683\r\n");
#endif
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：配置华为生命周期
 *
 *********************************************************************************
 **/
#if (PROJECT_TYPEDEF == NB_ONENET)
void AT_TX_MIPLCONFIG(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+MIPLCONFIG=2,1,2\r\n");
}
#endif
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：电信平台IP地址
 *
 *********************************************************************************
 **/
void AT_TX_NCDP(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+NCDP=221.229.214.202,5683\r\n");
}

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：下发控制类，关闭PSM、启动DRX下发延时10秒
 *
 *********************************************************************************
 **/
void AT_TX_CGDCONT(void)
{
	if (simType == SIM_CMCC)
		sprintf((char *)main_tx.my_at_sendbuf, "AT+CGDCONT=1,\"IP\",\"CMNBIOT1\"\r\n");
	else // if(nbInfo_t.simType == SIM_CTCC)
		sprintf((char *)main_tx.my_at_sendbuf, "AT+CGDCONT=1,\"IP\",\"psm0.eDRX0.ctnb\"\r\n");
}

/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：禁止PSM
 *
 *********************************************************************************
 **/
void AT_TX_CPSMS(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CPSMS=0\r\n");
}
void AT_TX_OPENLED(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QLEDMODE=1\r\n");
}
/**
 *********************************************************************************
 *
 *函数名称：
 *
 *函数参数：无
 *
 *函数返回值：无
 *
 *功能描述：自动注册模式
 *
 *********************************************************************************
 **/
void AT_TX_QREGSWT(void)
{
#if (PROJECT_TYPEDEF == NB_ONENET)
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QREGSWT=2\r\n");
#else
	sprintf((char *)main_tx.my_at_sendbuf, "AT+QREGSWT=1\r\n");
#endif
}

void AT_TX_CEDRXS(void)
{
	sprintf((char *)main_tx.my_at_sendbuf, "AT+CEDRXS=0,5\r\n");
}
#endif
